<template>
  <div id="bookMall">
    <com-head :opacity="0">书城</com-head>
    <div class="navbook">
      <div class="box" :class="{active: active === '1'}" @click="booklist">书籍</div>
      <div class="box" :class="{active: active === '2'}" @click="Ebooklist">电子书</div>
    </div>
    <div class="sellwell" v-if="active === '1'">
      <div
        class="bookList"
        @click="bookDetail(item.book_id)"
        v-for="(item,index) in bookList"
        :key="index"
      >
        <div class="left">
          <img :src="item.image">
        </div>
        <div class="right">
          <div class="name">{{item.name}}</div>
          <div class="abstract">{{item.book_sign}}</div>
          <!-- <div class="pagenum">共{{item.pagenum}}章</div> -->
        </div>
      </div>
    </div>
    <!-- 电子书 -->
    <div class="sellwell" v-if="active === '2'">
      <div
        class="bookList"
        @click="bookDetail(item.book_id)"
        v-for="(item,index) in ebookList"
        :key="index"
      >
        <div class="eleft">
          <img :src="item.cover">
        </div>
        <div class="right">
          <div class="name">{{item.name}}</div>
          <div class="abstract">{{item.book_sign}}</div>
          <div class="pagenum">共{{item.number}}章</div>
        </div>
      </div>
    </div>
    <com-foot :select="1"></com-foot>
  </div>
</template>

<script>
export default {
  name: "bookMall",
  data() {
    return {
      active: "1",
      ebookList: [],
      bookList: []
    };
  },

  computed: {},

  created() {
    if (this.$route.query.active === "0") {
      //电子书
      this.active = "2";
      this.loading2();
    } else {
      //实体书
      this.loading1();
    }
  },

  mounted() {},

  methods: {
    bookDetail(id) {
      if (this.active === "1") {
        //实体书
        this.$router.push({ name: "buy", query: { id: id } });
      } else if (this.active === "2") {
        //电子书
        this.$router.push({ name: "ebookDetail", query: { id: id } });
      }
    },
    loading1() {
      this.axios
        .post("index/book")
        .then(({ data }) => {
          console.log(data);
          if (data.code === "200") {
            this.bookList = data.data;
          } else if (data.code === "201") {
            this.$bus.$emit("toast", data.msg);
          } else if (data.code === "205") {
            this.$bus.$emit("toast", "暂无数据");
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    loading2() {
      this.axios
        .post("index/ebook")
        .then(({ data }) => {
          console.log(data);
          if (data.code === "200") {
            this.ebookList = data.data;
          } else if (data.code === "201") {
            this.$bus.$emit("toast", data.msg);
          } else if (data.code === "205") {
            this.$bus.$emit("toast", "暂无数据");
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    booklist() {
      this.active = "1";
      this.loading1();
    },
    Ebooklist() {
      this.active = "2";
      this.loading2();
    }
  }
};
</script>
<style lang='scss'>
#bookMall {
  #pageHead {
    .icon-fanhui {
      display: none;
    }
  }
  .navbook {
    position: fixed;
    top: 88px;
    width: 100%;
    height: 90px;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    border-bottom: 4px solid rgba(65, 215, 189, 1);
    color: rgba(65, 215, 189, 1);
    background-color: #fff;
    .box {
      width: 264px;
      height: 60px;
      margin-right: 10px;
      border-radius: 10px 10px 0px 0px;
      text-align: center;
      line-height: 60px;
      border: 1Px solid rgba(65, 215, 189, 1);
      border-bottom: none;
    }
    .active {
      background: rgba(65, 215, 189, 1);
      color: #fff;
    }
  }
  .sellwell {
    margin-top: 98px;
    background-color: #fff;
    padding: 0 32px;
    .bookList {
      height: 340px;
      border-bottom: 1Px solid #f6f6f6;
      display: flex;
      justify-content: space-between;
      .left {
        width: 200px;
        height: 260px;
        border-radius: 6px;
        margin-top: 40px;
        // border: 1Px solid #eee;
        box-shadow: 4px 4px 10px #aaa;
        overflow: hidden;
        img {
          display: block;
          width: 70%;
          height: 70%;
          margin: 38px auto;
        }
      }
      .eleft {
        width: 200px;
        height: 260px;
        border-radius: 6px;
        margin-top: 40px;
        overflow: hidden;
        // border: 1Px solid #eee;
        // box-shadow: 4px 4px 10px #aaa;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .right {
        width: 458px;
        height: 240px;
        margin-top: 60px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        font-size: 26px;
        color: rgba(153, 153, 153, 1);
        .name {
          color: #222;
          font-size: 30px;
        }
        .abstract {
          // height: 200px;
          line-height: 40px;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 3;
          overflow: hidden;
        }
      }
    }
  }
}
</style>